<?php
if(!defined('IN_WOGU')) {
    exit('Access Denied');
}

class PluginManager
{
    static protected $_plugins = array();

    static public function addPlugin($name, Plugin_Abstract $plugin, $type = 'system') {
        self::$_plugins[$type][$name] = $plugin;
    }

    static public function removePlugin($name, $type = 'system') {
        unset(self::$_plugins[$type][$name]);
    }

    static public function dispatchLoopStartup(Request $request, Respones $respones, $type = 'system') {
        if(isset(self::$_plugins[$type])) {
            foreach(self::$_plugins[$type] as $plugin) {
                $plugin->dispatchLoopStartup($request, $respones);
            }
        }
    }

    static public function dispatchLoopShutdown(Request $request, Respones $respones, $type = 'system') {
        if(isset(self::$_plugins[$type])) {
            foreach(self::$_plugins[$type] as $plugin) {
                $plugin->dispatchLoopShutdown($request, $respones);
            }
        }
    }

    static public function preDispatch(Request $request, Respones $respones, $type = 'system') {
        if(isset(self::$_plugins[$type])) {
            foreach(self::$_plugins[$type] as $plugin) {
                $plugin->preDispatch($request, $respones);
            }
        }
    }

    static public function postDispatch(Request $request, Respones $respones, $type = 'system') {
        if(isset(self::$_plugins[$type])) {
            foreach(self::$_plugins[$type] as $plugin) {
                $plugin->postDispatch($request, $respones);
            }
        }
    }
}
